import java.util.Stack;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 05 - 28
 * Time: 9:01
 */
class MinStack {
        private Stack<Integer> stack;
        private Stack<Integer> minStack;
        public MinStack() {
            stack = new Stack<>();
            minStack = new Stack<>();
        }
        public void push(int val) {
            if(stack.isEmpty() && minStack.isEmpty()) {
                stack.push(val);
                minStack.push(val);
            }else {
                if(val <= minStack.peek()) {
                    stack.push(val);
                    minStack.push(val);
                }else {
                    stack.push(val);
                }
            }
        }

    public void pop() {
        if(stack.isEmpty()) {
            return;
        }
        int num = minStack.peek();
        if(stack.peek() == num) {
            stack.pop();
            minStack.pop();
        }else {
            stack.pop();
        }
    }

        public int top() {
            return stack.peek();
        }

        public int getMin() {
            return minStack.peek();
        }
}



class MyCircularQueue {
    public int[] elem;
    public int front;
    public int rear;
    public MyCircularQueue(int k) {
        elem = new int[k + 1];
    }

    public boolean enQueue(int value) {
        if(isFull()) {
            return false;
        }else {
            elem[rear] = value;
            rear = (rear + 1) % elem.length;
            return true;
        }
    }

    public boolean deQueue() {
        if(isEmpty()) {
            return false;
        }else {
            front = (front + 1) % elem.length;
            return true;
        }
    }

    public int Front() {
        if(isEmpty()) {
            return -1;
        }else {
            return elem[front];
        }
    }

    public int Rear() {
        if(isEmpty()) {
            return -1;
        }else {
            int index = (rear == 0 ? elem.length - 1 : rear - 1);//或者int x = (rear + elem.length - 1) % elem.length;
            return elem[index];
        }
    }

    public boolean isEmpty() {
        return front == rear;
    }

    public boolean isFull() {
        if((rear + 1) % elem.length == front) {
            return true;
        }else {
            return false;
        }
    }
}
